package psn.qiuyiping.autocad.dxffile;

import java.util.Map;

@Dxf0Name("SECTION")
public class Section extends DefaultDxf0 {
    static final Map<String, Class<? extends Section>> SECTIONFUNCS;
    static {
        SECTIONFUNCS = new java.util.TreeMap<>();
        SECTIONFUNCS.put("HEADER", SectionHeader.class);
        SECTIONFUNCS.put("THUMBNAILIMAGE", SectionImage.class);
    }

    public Section() {
        super();
        fields.putAll(redo(Section.class));
    }

    @DxfCode(2)
    public void readSectionName(DxfProcessContext context, DxfData<String> sectionName) {
        Class<? extends Section> cls = SECTIONFUNCS.get(sectionName.val);
        System.out.println("sectionName:" + sectionName.val);
        if (cls == null) {
            return;
        }
        try {
            Section sf = cls.newInstance();
            context.pop();
            context.push(sf::readDxf);
        } catch (Exception e) {
            throw new IllegalArgumentException(cls.toString());
        }
    }
}
